package com.doit.day02

import com.doit.day01.Hero

import scala.io.Source

class ScalaIterator extends Iterator[Hero]{
  //打开文件
  private val lines: Iterator[String] = Source.fromFile("data/hero.txt").getLines()
  //定义一个方法
  //def 方法名(参数):返回值类型 = {}
  override def hasNext: Boolean = lines.hasNext
  override def next: Hero = {
    val line: String = lines.next()
    //1,张飞_18::40==100
    val arr: Array[String] = line.split(",")
    //张飞_18::40==100
    val arr1: Array[String] = arr(1).split("_")
    //18::40==100
    val arr2: Array[String] = arr1(1).split("::")
    //40==100
    val arr3: Array[String] = arr2(1).split("==")
    new Hero(arr(0).toInt,arr1(0),arr2(0).toInt,arr3(0).toDouble,arr3(1).toDouble)
  }
}
object Test1{
  def main(args: Array[String]): Unit = {
    val iterator: ScalaIterator = new ScalaIterator
    while (iterator.hasNext){
      println(iterator.next())
    }
  }
}
